Package weasel.compiler.keywords

Source Code of weasel.compiler.keywords.WeaselKeyWordCompilerBreak

package weasel.compiler.keywords;

import java.util.ListIterator;

import weasel.compiler.WeaselCompiler;
import weasel.compiler.WeaselCompilerException;
import weasel.compiler.WeaselCompilerReturn;
import weasel.compiler.WeaselInstructionList;
import weasel.compiler.WeaselKeyWordCompilerHelper;
import weasel.compiler.WeaselToken;
import weasel.compiler.WeaselTokenType;
import weasel.interpreter.bytecode.WeaselInstructionJump;

public class WeaselKeyWordCompilerBreak extends WeaselKeyWordCompiler {

  @Override
  public WeaselCompilerReturn compile(WeaselToken token, WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelpher, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
    WeaselToken t = iterator.next();
    int s = 1;
    if(t.tokenType==WeaselTokenType.INTEGER){
      s = (Integer)t.param;
      if(s<=0)
        throw new WeaselCompilerException(t.line, "Negatives and 0 are not permitted");
      t = iterator.next();
    }
    WeaselInstructionList instructionList = new WeaselInstructionList();
    compilerHelpher.addClosingsAndFrees(s, instructionList, true);
    WeaselInstructionJump breakJump;
    instructionList.add(token.line, breakJump = new WeaselInstructionJump());
    compilerHelpher.addBreak(s, breakJump);
    expect(t, WeaselTokenType.SEMICOLON);
    return null;
  }

}
TOP

Related Classes of weasel.compiler.keywords.WeaselKeyWordCompilerBreak

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.